import 'package:flutter/cupertino.dart';
////import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_module/beans/Entity.dart';
import 'package:flutter_module/commom/check.dart';
import 'package:flutter_module/http/view_model.dart';
import 'package:oktoast/oktoast.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../DemoLocalizations.dart';

EntityViewModel entityViewModel = new EntityViewModel();

class EntityViewModel extends ViewModel {
  /*
  * 按时间线获取事件
  * */
  Future<dynamic> getEntityNews(BuildContext context) async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    String uuid = sp.getString("uuid");
    //String uuid = "6e541b0d22654d5da17e700e7dd762c22c9885cf717449f601717449f6aa0000";
    if (uuid == null) {
      if (context != null) {
        showToast(DemoLocalizations.of(context).LoginFirst);
      }
    } else {
      final Map map = await EntityReqModel().data(uuid);
      List list = new List();
      if (map != null && map.isNotEmpty) {
        if (map['result'] == null) {
          showToast(DemoLocalizations.of(context).NoEquipment);
        } else {
          final data = map['result']['app_esp_ip'];
          if (listNoEmpty(data)) {
            data.forEach((json) => list.add(App_esp_ip.fromJson(json)));
          } else {
            showToast(DemoLocalizations.of(context).NoEquipment);
          }
        }
      }
      return Future.value(list);
    }
  }
}
